using UnityEngine;
using System.Collections.Generic;
public static class SpriteRendererExtensions
{
    public static Vector2 GetShapeCenterInWorld(this SpriteRenderer sprite,float minDis=0.3f)
    {

        List<Vector2> path = new List<Vector2>();
        var ans = Vector2.zero;
        int cnt = 0;
        List<Vector2> points = new List<Vector2>();
        for (int i = 0; i < sprite.sprite.GetPhysicsShapeCount(); i++)
        {
            path.Clear();
            sprite.sprite.GetPhysicsShape(i, path);
            foreach(var x in path)
            {
                if (points.Find(s => Vector2.Distance(x, s) < minDis) != default)
                {
                    continue;
                }
                ans = ans + x;
                cnt++;
                points.Add(x);
                break;
            }
        }
        Debug.Log("cnt=" + cnt);
        return sprite.transform.TransformPoint(ans / cnt);
    }
}